﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace LVTN
{
    //this class is used save data like object to transfer between client and server

    [Serializable()]
    class myStruct : ISerializable
    {
        private Socket mySocket;
        private double[,] data;// data
        private int count;// check data
        private int matrixsize;// matrix size
        private int thread;// number thread client
        private int sr;

        public int Sr
        {
            get { return sr; }
            set { sr = value; }
        }
        private int er;

        public int Er
        {
            get { return er; }
            set { er = value; }
        }

        public myStruct()
        {
            this.mySocket = null;
            this.data = null;
            this.count = 0;
            this.matrixsize = 0;
            this.thread = 0;
            this.er = 0;
            this.sr = 0;

        }

        public myStruct(myStruct str)
        {
            this.mySocket = str.mySocket;
            this.data = str.data;
            this.count = str.count;
            this.matrixsize = str.matrixsize;
            this.thread = str.thread;
            this.er = str.er;
            this.sr = str.sr;
        }

        public myStruct(Socket mySocket1, double[,] data1, int count1, int matrixsize1, int thread1, int sr1, int er1)
        {
            this.mySocket = mySocket1;
            this.data = data1;
            this.count = count1;
            this.matrixsize = matrixsize1;
            this.thread = thread1;
            this.sr = sr1;
            this.er = er1;
        }

        //Serialize data

        public void GetObjectData(SerializationInfo info, StreamingContext strcxt)
        {
            //     info.AddValue("socket", this.mySocket);
            info.AddValue("count", this.count);
            info.AddValue("data", this.data);
            info.AddValue("matrixsize", this.matrixsize);
            info.AddValue("thread", this.thread);
            info.AddValue("sr", this.sr);
            info.AddValue("er", this.er);

        }

        //Deserilize data

        private myStruct(SerializationInfo info, StreamingContext strcxt)
        {
            //     this.mySocket = (Socket)info.GetValue("socket", typeof(Socket));
            this.count = (int)info.GetValue("count", typeof(int));
            this.data = (double[,])info.GetValue("data", typeof(double[,]));
            this.matrixsize = (int)info.GetValue("matrixsize", typeof(int));
            this.thread = (int)info.GetValue("thread", typeof(int));
            this.sr = (int)info.GetValue("sr", typeof(int));
            this.er = (int)info.GetValue("er", typeof(int));
        }

        public Socket MySocket
        {
            get { return mySocket; }
            set { mySocket = value; }
        }

        public double[,] Data
        {
            get { return data; }
            set { data = value; }
        }

        public int Matrixsize
        {
            get { return matrixsize; }
            set { matrixsize = value; }
        }

        public int Thread
        {
            get { return thread; }
            set { thread = value; }
        }

        public int Count
        {
            get { return count; }
            set { count = value; }
        }

    }
}
